<HTML><HEAD><TITLE>sgn(+Number, -Result)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Arithmetic</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>sgn(+Number, -Result)</H1>
Unifies Result with the sign of Number which is either -1, 0 or 1.


<DL>
<DT><EM>Number</EM></DT>
<DD>A number.
</DD>
<DT><EM>Result</EM></DT>
<DD>A variable or an integer.
</DD>
</DL>
<H2>Description</H2>
   This predicate is used by the ECLiPSe compiler to expand evaluable
   arithmetic expressions.  So the call to sgn(Number, Result) is
   equivalent to
<PRE>
    Result is sgn(Number)
</PRE>
    which should be preferred for portability.
<P>
   sgn/2 gives the integer -1 if Number is negative, 0 if it is zero and 1
   if it is greater than zero.  It is always true that
<PRE>
    X =:= sgn(X) * abs(X)
</PRE>
   In coroutining mode, if Number is uninstantiated, the call to sgn/2 is
   delayed until this variable is instantiated.

<H3>Modes and Determinism</H3><UL>
<LI>sgn(+, -) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Number is not instantiated (non-coroutining mode only).
<DT><EM>(24) number expected </EM>
<DD>Number is not of a numeric type.
</DL>
<H2>Examples</H2>
<PRE>
Success:
      sgn(42, 1).
      sgn(-5, Result).             (gives Result = -1)
      sgn(-6.2, Result).           (gives Result = -1)
      sgn(0.0, 0).
Fail:
      sgn(1, 0).
      sgn(1, 1.0).
      sgn(1, r).
Error:
      sgn(A, 6).                   (Error 4).
      sgn(4 + 2, 6).               (Error 24).



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/arithmetic/is-2.html">is / 2</A>
</BODY></HTML>
